package easy;

public class Solution_1422 {

    public int maxScore(String s) {
        char[] array = s.toCharArray();
        int[] ints_1 = new int[s.length() + 1];
        int[] ints_2 = new int[s.length() + 1];
        for (int i = 0, j = array.length - 1; i < array.length; i++, j--) {
            if (array[i] == '0') {
                ints_1[i + 1] = ints_1[i] + 1;
            } else {
                ints_1[i + 1] = ints_1[i];
            }
            if (array[j] == '1') {
                ints_2[j] = ints_2[j + 1] + 1;
            } else {
                ints_2[j] = ints_2[j + 1];
            }
        }
        int max = 0;
        for (int i = 1; i < ints_1.length-1; i++) {
            int val = ints_1[i] + ints_2[i];
            if (val > max) {
                max = val;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        Solution_1422 model = new Solution_1422();
        System.out.println(model.maxScore("011101"));
        System.out.println(model.maxScore("00111"));
        System.out.println(model.maxScore("1111"));
        System.out.println(model.maxScore("0000"));
    }
}
